package com.alander.nexusgo.framework.redis.starter.key;

import org.springframework.beans.factory.annotation.Value;

public abstract class RedisKeyBuilder {

    @Value("${spring.application.name}")
    private String applicationName;

    private static final String SPLIT_ITEM = ":";

    protected String buildKey(String... components) {
        StringBuilder keyBuilder = new StringBuilder(applicationName).append(SPLIT_ITEM);
        for (int i = 0; i < components.length; i++) {
            keyBuilder.append(components[i]);
            if (i < components.length - 1) {
                keyBuilder.append(SPLIT_ITEM);
            }
        }
        return keyBuilder.toString();
    }
}